/**
 * \file sgi_link_layer.c
 *
 * \brief definition file of SGI library to handle the sgi link layer bursts
 *
 * \author Santiago Carmona Meco
 *
 * Contact santiago.carmonads@gmail.com
 *
 */

// ****************************************
// 	CHANGE LOG
//                OCT-2011  scarmona  Creating this file
//                2011-2012 scarmona  Development of the library and source code modifications
//                FEB-2013  scarmona  Modifications of type names, variable names and update
// 									  of comments with format of doxygen
//				  26-4-2013 scarmona  Subtle modifications of code style and type definitions in burst structs
//				  21-6-2013 scarmona  Changes in parameters of builder functions
//
// ****************************************


#include <public/sgi_link_layer.h>


//******************************************************
//sgi_link_layer_get_burst_info_type();
//******************************************************
void sgi_link_layer_get_burst_info_type(byte_t * pBurstHeader, SGI_burst_t * pBurstInfo)
{
//	pBurstInfo->code = sgi_link_layer_get_code(pBurstHeader);
//	pBurstInfo->crtl = sgi_link_layer_get_ctrl_flags(pBurstHeader);
//	sgi_link_layer_get_key(pBurstHeader, pBurstInfo->key);
//
//	switch (pBurstInfo->code)//no hace falta default, se supone q si entra aquí esta bien
//	{//dummy no es necesario
//		case MASK_BURST_A_SGI:
//			sgi_link_layer_get_univ_time(pBurstHeader, pBurstInfo->burst_type_info.type_a_info.univ_time);
//			pBurstInfo->burst_type_info.type_a_info.nf = sgi_link_layer_get_nf(pBurstHeader);
//			break;
//		case MASK_BURST_B_SGI:
//			sgi_link_layer_get_size_req_2(pBurstHeader, pBurstInfo->burst_type_info.type_b_info.size_req);
//			sgi_link_layer_get_size_provide_2(pBurstHeader, pBurstInfo->burst_type_info.type_b_info.size_provide);
//			break;
//		case MASK_BURST_C_SGI:
//			sgi_link_layer_get_acks_2(pBurstHeader, pBurstInfo->burst_type_info.type_c_info.acks); //DUMMY no es necesario;
//			pBurstInfo->burst_type_info.type_a_info.nf = sgi_link_layer_get_nf(pBurstHeader);
//			break;
//		case MASK_BURST_D_SGI:
//			sgi_link_layer_get_acks_2(pBurstHeader, pBurstInfo->burst_type_info.type_d_info.acks);
//			pBurstInfo->burst_type_info.type_d_info.gc = sgi_link_layer_get_gc(pBurstHeader);
//			pBurstInfo->burst_type_info.type_d_info.ss = sgi_link_layer_get_ss(pBurstHeader);
//			pBurstInfo->burst_type_info.type_d_info.sd = sgi_link_layer_get_sd(pBurstHeader);
//			pBurstInfo->burst_type_info.type_d_info.nf = sgi_link_layer_get_nf(pBurstHeader);
//			break;
//		case MASK_BURST_E_SGI:
//			sgi_link_layer_get_stats_tx(pBurstHeader, pBurstInfo->burst_type_info.type_e_info.stats_tx);
//			sgi_link_layer_get_stats_rx(pBurstHeader, pBurstInfo->burst_type_info.type_e_info.stats_rx);
//			break;
//		case MASK_BURST_F_SGI:
//			//nada, todo dummy
//			break;
//	}
}

//TODO: This function only is used in its own unitary test, it has not any sense
//******************************************************
//sgi_link_layer_get_burst_info();
//******************************************************
bool_t sgi_link_layer_get_burst_info(byte_t * pBurstHeader, SGI_burst_t * pBurstInfo)
{
//	word16_t crcBurst;
//	word16_t crcBurstBis;
//
//	crcBurst = pBurstHeader[14];
//	crcBurst = crcBurst << 8;
//	crcBurst = crcBurst + pBurstHeader[15];
//	crcBurstBis = pBurstHeader[30];
//	crcBurstBis = crcBurstBis << 8;
//	crcBurstBis = crcBurstBis + pBurstHeader[31];
//
//	if (check_CRC_word16(14, pBurstHeader, crcBurst))
//	{
//		sgi_link_layer_get_burst_info_type(pBurstHeader, pBurstInfo);
//		return 1;
//	}
//	else if (check_CRC_word16(14, (pBurstHeader + 16), crcBurstBis))
//	{
//		sgi_link_layer_get_burst_info_type((pBurstHeader + 16), pBurstInfo);
//		return 1;
//	}
//	else
//	{
//		return 0;
//	}
	return 1;
}

//******************************************************
//sgi_link_layer_check_crcs();
//******************************************************
bool_t sgi_link_layer_check_crcs(byte_t * pBurstHeader, int8_t *offSet)
{
	word16_t crcBurst;
	word16_t crcBurstBis;

	(*offSet) = 0;
	crcBurst = pBurstHeader[14];
	crcBurst = crcBurst << 8;
	crcBurst = crcBurst + pBurstHeader[15];
	crcBurstBis = pBurstHeader[30];
	crcBurstBis = crcBurstBis << 8;
	crcBurstBis = crcBurstBis + pBurstHeader[31];

	if (check_CRC_word16(14, pBurstHeader, crcBurst))
	{
		return 1;
	}
	else if (check_CRC_word16(14, (pBurstHeader + 16), crcBurstBis))
	{
		(*offSet) = 16;
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_add_crc_to_frame();
//******************************************************
void sgi_link_layer_add_crc_to_frame(byte_t * pBurstHeader)//quitar de aquí y poner en ssi linklayer
{
	word16_t codigoCRC;

	codigoCRC = calculate_CRC_word16(14, pBurstHeader);
	pBurstHeader[15] = codigoCRC;
	pBurstHeader[14] = codigoCRC >> 8;

}

//******************************************************
//sgi_link_layer_get_code();
//******************************************************
byte_t sgi_link_layer_get_code(byte_t * pBurstHeader)
{
	return pBurstHeader[0];
}

//******************************************************
//sgi_link_layer_get_ctrl_flags();
//******************************************************
byte_t sgi_link_layer_get_ctrl_flags(byte_t * pBurstHeader)
{
	return pBurstHeader[1];
}

//******************************************************
//sgi_link_layer_get_key();
//******************************************************
void sgi_link_layer_get_key(byte_t * pBurstHeader, byte_t *pKey)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pKey[i] = pBurstHeader[2 + i];
		i++;
	}

}

//******************************************************
//sgi_link_layer_get_key_code();
//******************************************************
void sgi_link_layer_get_key_code(byte_t * pBurstHeader, byte_t *pKeyCode)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pKeyCode[i] = pBurstHeader[2 + i];
		i++;
	}

}

//******************************************************
//sgi_link_layer_get_univ_time();
//******************************************************
void sgi_link_layer_get_univ_time(byte_t * pBurstHeader, byte_t *pUnivTime)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pUnivTime[i] = pBurstHeader[6 + i];
		i++;
	}

}

//******************************************************
//sgi_link_layer_get_size_req();
//******************************************************
word32_t sgi_link_layer_get_size_req(byte_t * pBurstHeader)
{
	word32_t sizeReq;
	uint8_t i = 1;

	sizeReq = pBurstHeader[9];

	while (i < 4)
	{
		sizeReq = sizeReq << 8;
		sizeReq = sizeReq + pBurstHeader[9 - i];
		i++;
	}
	return sizeReq;
}

//******************************************************
//sgi_link_layer_get_acks();
//******************************************************
word32_t sgi_link_layer_get_acks(byte_t * pBurstHeader)
{
	word32_t acks;
	uint8_t i = 1;

	acks = pBurstHeader[9];

	while (i < 4)
	{
		acks = acks << 8;
		acks = acks + pBurstHeader[9 - i];
		i++;
	}
	return acks;
}

//******************************************************
//sgi_link_layer_get_stats_tx();
//******************************************************
void sgi_link_layer_get_stats_tx(byte_t * pBurstHeader, byte_t *pStatsTx)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pStatsTx[i] = pBurstHeader[6 + i];
		i++;
	}

}

//******************************************************
//sgi_link_layer_get_stats_rx();
//******************************************************
void sgi_link_layer_get_stats_rx(byte_t * pBurstHeader, byte_t *pStatsRx)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pStatsRx[i] = pBurstHeader[10 + i];
		i++;
	}

}

//******************************************************
//sgi_link_layer_get_size_provide();
//******************************************************
word32_t sgi_link_layer_get_size_provide(byte_t * pBurstHeader)
{
	word32_t sizeProvide;
	uint8_t i = 1;

	sizeProvide = pBurstHeader[13];

	while (i < 4)
	{
		sizeProvide = sizeProvide << 8;
		sizeProvide = sizeProvide + pBurstHeader[13 - i];
		i++;
	}
	return sizeProvide;
}

//******************************************************
//sgi_link_layer_get_crc();
//******************************************************
word16_t sgi_link_layer_get_crc(byte_t *pBurstHeader)
{
	word16_t crc = 0;

	crc = pBurstHeader[6];
	crc = crc << 8;
	crc = crc + pBurstHeader[7];

	return crc;
}

//******************************************************
//sgi_link_layer_get_nf();
//******************************************************
byte_t sgi_link_layer_get_nf(byte_t * pBurstHeader)
{
	return pBurstHeader[13];
}

//******************************************************
//sgi_link_layer_get_gc();
//******************************************************
byte_t sgi_link_layer_get_gc(byte_t * pBurstHeader)
{
	return pBurstHeader[10];
}

//******************************************************
//sgi_link_layer_get_ss();
//******************************************************
byte_t sgi_link_layer_get_ss(byte_t * pBurstHeader)
{
	return pBurstHeader[11];
}

//******************************************************
//sgi_link_layer_get_sd();
//******************************************************
byte_t sgi_link_layer_get_sd(byte_t * pBurstHeader)
{
	return pBurstHeader[12];
}

//******************************************************
//sgi_link_layer_is_ack();
//******************************************************
bool_t sgi_link_layer_is_ack(byte_t * pBurstHeader)
{

	if ((MASK_ACK_SGI & pBurstHeader[1]) == MASK_ACK_SGI)
	{
		return 1;
	}
	else
	{
		return 0;
	}

}

//******************************************************
//sgi_link_layer_is_yield();
//******************************************************
bool_t sgi_link_layer_is_yield(byte_t * pBurstHeader)
{
	if ((MASK_YIELD_SGI & pBurstHeader[1]) == MASK_YIELD_SGI)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_space();
//******************************************************
bool_t sgi_link_layer_is_space(byte_t * pBurstHeader)
{
	if ((MASK_SPACE_SGI & pBurstHeader[1]) == MASK_SPACE_SGI)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_ground();
//******************************************************
bool_t sgi_link_layer_is_ground(byte_t * pBurstHeader)
{
	if ((MASK_GROUND_SGI & pBurstHeader[1]) == MASK_GROUND_SGI)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_data();
//******************************************************
bool_t sgi_link_layer_is_data(byte_t * pBurstHeader)
{
	if ((MASK_DATA_SGI & pBurstHeader[1]) == MASK_DATA_SGI)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_alt();
//******************************************************
bool_t sgi_link_layer_is_alt(byte_t * pBurstHeader)
{
	if ((MASK_ALT_SGI & pBurstHeader[1]) == MASK_ALT_SGI)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_rep();
//******************************************************
bool_t sgi_link_layer_is_rep(byte_t * pBurstHeader)
{
	if ((MASK_REP_SGI & sgi_link_layer_get_ctrl_flags(pBurstHeader)) == MASK_REP_SGI)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sat_tc_frames();
//******************************************************
bool_t sgi_link_layer_is_sat_tc_frames(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SAT_TC_FRAMES) == MASK_SAT_TC_FRAMES)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
//******************************************************
//sgi_link_layer_is_last_sat_tc_frames();
//******************************************************
bool_t sgi_link_layer_is_last_sat_tc_frames(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_LAST_SAT_TC_FRAMES) == MASK_LAST_SAT_TC_FRAMES)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sat_tm_frames();
//******************************************************
bool_t sgi_link_layer_is_sat_tm_frames(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SAT_TM_FRAMES) == MASK_SAT_TM_FRAMES)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_last_sat_tm_frames();
//******************************************************
bool_t sgi_link_layer_is_last_sat_tm_frames(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_LAST_SAT_TM_FRAMES) == MASK_LAST_SAT_TM_FRAMES)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sat_tm_frames_ack();
//******************************************************
bool_t sgi_link_layer_is_sat_tm_frames_ack(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SAT_TM_FRAMES_ACK) == MASK_SAT_TM_FRAMES_ACK)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
//******************************************************
//sgi_link_layer_is_last_sat_tm_frames_ack();
//******************************************************
bool_t sgi_link_layer_is_last_sat_tm_frames_ack(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_LAST_SAT_TM_FRAMES_ACK) == MASK_LAST_SAT_TM_FRAMES_ACK)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
//******************************************************
//sgi_link_layer_is_sat_tc_frames_ack();
//******************************************************
bool_t sgi_link_layer_is_sat_tc_frames_ack(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SAT_TC_FRAMES_ACK) == MASK_SAT_TC_FRAMES_ACK)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sat_burst_nack();
//******************************************************
bool_t sgi_link_layer_is_sat_burst_nack(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SAT_BURST_NACK) == MASK_SAT_BURST_NACK)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_srg_humsat_ready();
//******************************************************
bool_t sgi_link_layer_is_srg_humsat_ready(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SRG_HUMSAT_READY) == MASK_SRG_HUMSAT_READY)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sen_tmtc_del_req();
//******************************************************
bool_t sgi_link_layer_is_sen_tmtc_del_req(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_TMTC_DEL_REQ) == MASK_SEN_TMTC_DEL_REQ)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sen_tmtc_del_accept();
//******************************************************
bool_t sgi_link_layer_is_sen_tmtc_del_accept(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_TMTC_DEL_ACCEPT) == MASK_SEN_TMTC_DEL_ACCEPT)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sen_tmtc_del_end();
//******************************************************
bool_t sgi_link_layer_is_sen_tmtc_del_end(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_TMTC_DEL_END) == MASK_SEN_TMTC_DEL_END)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sen_tmtc_del_end_ack();
//******************************************************
bool_t sgi_link_layer_is_sen_tmtc_del_end_ack(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_TMTC_DEL_END_ACK) == MASK_SEN_TMTC_DEL_END_ACK)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sen_tc_sgi_link_frames();
//******************************************************
bool_t sgi_link_layer_is_sen_tc_sgi_link_frames(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_TC_SGI_LINK_FRAMES) == MASK_SEN_TC_SGI_LINK_FRAMES)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_last_sen_tc_sgi_link_frames();
//******************************************************
bool_t sgi_link_layer_is_last_sen_tc_sgi_link_frames(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_LAST_TC_SGI_LINK_FRAMES) == MASK_SEN_LAST_TC_SGI_LINK_FRAMES)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sen_tm_sgi_link_frames();
//******************************************************
bool_t sgi_link_layer_is_sen_tm_sgi_link_frames(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_TM_SGI_LINK_FRAMES) == MASK_SEN_TM_SGI_LINK_FRAMES)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_last_sen_tm_sgi_link_frames();
//******************************************************
bool_t sgi_link_layer_is_last_sen_tm_sgi_link_frames(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_LAST_TM_SGI_LINK_FRAMES) == MASK_SEN_LAST_TM_SGI_LINK_FRAMES)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_last_sen_tm_sgi_link_frames_ack();
//******************************************************
bool_t sgi_link_layer_is_last_sen_tm_sgi_link_frames_ack(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_LAST_TM_SGI_LINK_FRAMES_ACK) == MASK_SEN_LAST_TM_SGI_LINK_FRAMES_ACK)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sen_tc_sgi_link_frames_ack();
//******************************************************
bool_t sgi_link_layer_is_sen_tc_sgi_link_frames_ack(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_TC_SGI_LINK_FRAMES_ACK) == MASK_SEN_TC_SGI_LINK_FRAMES_ACK)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

//******************************************************
//sgi_link_layer_is_sen_tm_sgi_link_frames_ack();
//******************************************************
bool_t sgi_link_layer_is_sen_tm_sgi_link_frames_ack(byte_t *pBurstHeader)
{
	if ((sgi_link_layer_get_ctrl_flags(pBurstHeader) & MASK_SEN_TM_SGI_LINK_FRAMES_ACK) == MASK_SEN_TM_SGI_LINK_FRAMES_ACK)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}


//******************************************************
//sgi_link_layer_build_header_burst_type_a();
//******************************************************
void sgi_link_layer_build_header_burst_type_a(byte_t * pBurstHeader, SGI_burst_A_t burst)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pBurstHeader[i + 6] = burst.univ_time[i];
		i++;
	}

	i = 0;
	while (i < 3)
	{
		pBurstHeader[i + 10] = burst.dummy[i];
		i++;
	}
	pBurstHeader[13] = burst.nf;
}

//******************************************************
//sgi_link_layer_build_header_burst_type_b();
//******************************************************
void sgi_link_layer_build_header_burst_type_b(byte_t * pBurstHeader, SGI_burst_B_t burst)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pBurstHeader[i + 6] = burst.size_req[i];
		i++;
	}

	i = 0;
	while (i < 4)
	{
		pBurstHeader[i + 10] = burst.size_provide[i];
		i++;
	}
}

//******************************************************
//sgi_link_layer_build_header_burst_type_c();
//******************************************************
void sgi_link_layer_build_header_burst_type_c(byte_t * pBurstHeader, SGI_burst_C_t burst)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pBurstHeader[i + 6] = burst.acks[i];
		i++;
	}

	i = 0;
	while (i < 3)
	{
		pBurstHeader[i + 10] = burst.dummy[i];
		i++;
	}
	pBurstHeader[13] = burst.nf;
}

//******************************************************
//sgi_link_layer_build_header_burst_type_d();
//******************************************************
void sgi_link_layer_build_header_burst_type_d(byte_t * pBurstHeader, SGI_burst_D_t burst)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pBurstHeader[i + 6] = burst.acks[i];
		i++;
	}
	pBurstHeader[10] = burst.gc;
	pBurstHeader[11] = burst.ss;
	pBurstHeader[12] = burst.sd;
	pBurstHeader[13] = burst.nf;
}

//******************************************************
//sgi_link_layer_build_header_burst_type_e();
//******************************************************
void sgi_link_layer_build_header_burst_type_e(byte_t * pBurstHeader, SGI_burst_E_t burst)
{
	uint8_t i = 0;

	while (i < 4)
	{
		pBurstHeader[i + 6] = burst.stats_tx[i];
		i++;
	}

	i = 0;
	while (i < 4)
	{
		pBurstHeader[i + 10] = burst.stats_rx[i];
		i++;
	}
}

//******************************************************
//sgi_link_layer_build_header_burst_type_f();
//******************************************************
void sgi_link_layer_build_header_burst_type_f(byte_t * pBurstHeader, SGI_burst_F_t burst)
{
	uint8_t i = 0;

	while (i < 8)
	{
		pBurstHeader[i + 6] = burst.dummy[i];
		i++;
	}

}

//TODO: Se puede simplificar mucho MUCHÍSIMO haciendolo como está hecho
//en lo del high_level_can_service, y se hace en un ratejo
//******************************************************
//get_burst_type();
//******************************************************
BurstTypeReceived_t sgi_link_layer_get_burst_type(byte_t * pBurstHeader)
{
	switch (sgi_link_layer_get_code(pBurstHeader))
	{
		case MASK_BURST_A_SGI:
			if (sgi_link_layer_is_srg_humsat_ready(pBurstHeader))
			{
				return BurstTypeIsSrgHumsatReady;
			}
			else
			{
				return BurstTypeIsSGIDefault;
			}
			break;
		case MASK_BURST_B_SGI:
			if (sgi_link_layer_is_sen_tmtc_del_req(pBurstHeader))
			{
				return BurstTypeIsSenTMTCDelReq;
			}
			else if (sgi_link_layer_is_sen_tmtc_del_accept(pBurstHeader))
			{
				return BurstTypeIsSenTMTCDelAccept;
			}
			else
			{
				return BurstTypeIsSGIDefault;
			}
			break;
		case MASK_BURST_C_SGI:
			if (sgi_link_layer_is_sen_tc_sgi_link_frames(pBurstHeader))
			{
				return BurstTypeIsSenTCSgiLinkFrames;
			}
			else if (sgi_link_layer_is_sen_tm_sgi_link_frames(pBurstHeader))
			{
				return BurstTypeIsSenTMSgiLinkFrames;
			}
			else if (sgi_link_layer_is_sen_tm_sgi_link_frames_ack(pBurstHeader))
			{
				return BurstTypeIsSenTMSgiLinkFramesAck;
			}
			else if (sgi_link_layer_is_sen_tc_sgi_link_frames_ack(pBurstHeader))
			{
				return BurstTypeIsSenTCSgiLinkFramesAck;
			}
			else
			{
				return BurstTypeIsSGIDefault;
			}
			break;
		case MASK_BURST_D_SGI:
			if (sgi_link_layer_is_sat_tc_frames(pBurstHeader))
			{
				return BurstTypeIsSatTCFrames;
			}
			else if (sgi_link_layer_is_sat_tm_frames(pBurstHeader))
			{
				return BurstTypeIsSatTMFrames;
			}
			else if (sgi_link_layer_is_sat_tc_frames_ack(pBurstHeader))
			{
				return BurstTypeIsSatTCFramesAck;
			}
			else if (sgi_link_layer_is_sat_tm_frames_ack(pBurstHeader))
			{
				return BurstTypeIsSatTMFramesAck;
			}
			else
			{
				return BurstTypeIsSGIDefault;
			}
			break;
		case MASK_BURST_E_SGI:
			if (sgi_link_layer_is_sen_tmtc_del_end(pBurstHeader))
			{
				return BurstTypeIsSenTMTCDelEnd;
			}
			else if (sgi_link_layer_is_sen_tmtc_del_end_ack(pBurstHeader))
			{
				return BurstTypeIsSenTMTCDelEndAck;
			}
			else
			{
				return BurstTypeIsSGIDefault;
			}
			break;
		case MASK_BURST_F_SGI:
			if (sgi_link_layer_is_sat_burst_nack(pBurstHeader))
			{
				return BurstTypeIsSatBurstNack;
			}
			else
			{
				return BurstTypeIsSGIDefault;
			}
			break;
		default:
			return BurstTypeIsSGIDefault;
	}
}

//******************************************************
//sgi_link_layer_build_header_burst();
//******************************************************
void sgi_link_layer_build_header_burst(byte_t * pBurstHeader, SGI_burst_t burst)
{
	uint8_t i = 0;

	pBurstHeader[0] = burst.code;
	pBurstHeader[1] = burst.crtl;
	while (i < 4)
	{
		pBurstHeader[i + 2] = burst.key[i];
		i++;
	}
	switch (burst.code)
	{
		case MASK_BURST_A_SGI://TODO: aunque el dummy de igual algo habrá que montar para que no sea null
			sgi_link_layer_build_header_burst_type_a(pBurstHeader, burst.burst_type_info.type_a_info);
			break;//TODO:probar sin el * en el struct de la cabecera
		case MASK_BURST_B_SGI:
			sgi_link_layer_build_header_burst_type_b(pBurstHeader, burst.burst_type_info.type_b_info);
			break;
		case MASK_BURST_C_SGI:
			sgi_link_layer_build_header_burst_type_c(pBurstHeader, burst.burst_type_info.type_c_info);
			break;
		case MASK_BURST_D_SGI:
			sgi_link_layer_build_header_burst_type_d(pBurstHeader, burst.burst_type_info.type_d_info);
			break;
		case MASK_BURST_E_SGI:
			sgi_link_layer_build_header_burst_type_e(pBurstHeader, burst.burst_type_info.type_e_info);
			break;
		case MASK_BURST_F_SGI:
			sgi_link_layer_build_header_burst_type_f(pBurstHeader, burst.burst_type_info.type_f_info);
			//nada, todo dummy
			break;
	}
	sgi_link_layer_add_crc_to_frame(pBurstHeader);
}

//******************************************************
//build_sgi_ready_burst();
//******************************************************
void sgi_link_layer_build_sgi_ready_burst(byte_t *pReadyBurst, byte_t numberOfFrames, bool_t alt, byte_t *pAltBit)
{
	SGI_burst_t readyBurstAux;
	uint8_t i = 0;

	readyBurstAux.code = MASK_BURST_A_SGI;
	readyBurstAux.crtl = MASK_SRG_HUMSAT_READY;
	if (alt)
	{
		(*pAltBit) = sgi_link_layer_changes_alt_bit(&readyBurstAux.crtl, (*pAltBit));
	}
	while (i < 4)
	{

		readyBurstAux.key[i] = 1;
		readyBurstAux.burst_type_info.type_a_info.univ_time[i] = 0;
		i++;
	}
	i = 0;
	while (i < 3)
	{
		readyBurstAux.burst_type_info.type_a_info.dummy[i] = 0;
		i++;
	}

	if (numberOfFrames>32)//never should be more of 32 frames
	{
		readyBurstAux.burst_type_info.type_a_info.nf = 32;
	}
	else
	{
		readyBurstAux.burst_type_info.type_a_info.nf = numberOfFrames;
	}

	sgi_link_layer_build_header_burst(pReadyBurst, readyBurstAux);
	sgi_link_layer_build_header_burst((pReadyBurst + 16), readyBurstAux);
}
//******************************************************
//build_final_frame();
//******************************************************
void sgi_link_layer_build_final_frame(word16_t *pHeader, word16_t *pFrames, word16_t *finalFrame)
{
	uint32_t i = 0;

	while (i < 16)
	{
		finalFrame[i] = pHeader[i];
		i++;
	}

	i = 0;
	while (i < LENGTH_DATA_FRAMES_IN_WORDS)
	{
		finalFrame[i + 16] = pFrames[i];
		i++;
	}

}

//******************************************************
//build_tc_ack();
//******************************************************
void sgi_link_layer_build_tc_ack(byte_t *pHeaderBurst, word32_t acks, bool_t alt, int32_t tryNumber, byte_t *pAltBit)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_D_SGI;
	if (tryNumber > 0)
	{
		headerBurstAux.crtl = MASK_SAT_TC_FRAMES_ACK | MASK_REP_SGI;
	}
	else
	{
		headerBurstAux.crtl = MASK_SAT_TC_FRAMES_ACK;
	}
	if (alt)
	{
		(*pAltBit) = sgi_link_layer_changes_alt_bit(&headerBurstAux.crtl, (*pAltBit));
	}
	for (i = 0; i < 4; i++)
	{

		headerBurstAux.key[i] = 1;

	}
	headerBurstAux.burst_type_info.type_d_info.acks[0] = acks;
	headerBurstAux.burst_type_info.type_d_info.acks[1] = acks >> 8;
	headerBurstAux.burst_type_info.type_d_info.acks[2] = acks >> 16;
	headerBurstAux.burst_type_info.type_d_info.acks[3] = acks >> 24;
	headerBurstAux.burst_type_info.type_d_info.nf = 0;
	headerBurstAux.burst_type_info.type_d_info.gc = 0;
	headerBurstAux.burst_type_info.type_d_info.ss = 0;
	headerBurstAux.burst_type_info.type_d_info.sd = 0;

	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}

//******************************************************
//header_tm_frame();
//******************************************************
void sgi_link_layer_build_header_tm_frame(byte_t *pHeaderBurst, word32_t acks, byte_t numberOfFrames, bool_t alt, int32_t tryNumber, byte_t *pAltBit)

{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_D_SGI;

	for (i = 0; i < 4; i++)
	{

		headerBurstAux.key[i] = 1;
		/**
		 * TODO: revisar el orden de los bits en los arrays
		 */
		headerBurstAux.burst_type_info.type_d_info.acks[0] = acks;
		headerBurstAux.burst_type_info.type_d_info.acks[1] = acks >> 8;
		headerBurstAux.burst_type_info.type_d_info.acks[2] = acks >> 16;
		headerBurstAux.burst_type_info.type_d_info.acks[3] = acks >> 24;

	}
	if (numberOfFrames > 32)
	{
		headerBurstAux.burst_type_info.type_d_info.nf = 32;
		headerBurstAux.crtl = MASK_SAT_TM_FRAMES;
	}
	else
	{
		headerBurstAux.burst_type_info.type_d_info.nf = numberOfFrames;
		headerBurstAux.crtl = MASK_LAST_SAT_TM_FRAMES;
	}
	if (tryNumber > 0)
	{
		headerBurstAux.crtl = headerBurstAux.crtl | MASK_REP_SGI;
	}
	if (alt)
	{
		(*pAltBit) = sgi_link_layer_changes_alt_bit(&headerBurstAux.crtl, (*pAltBit));
	}
	headerBurstAux.burst_type_info.type_d_info.gc = 0;
	headerBurstAux.burst_type_info.type_d_info.ss = 0;
	headerBurstAux.burst_type_info.type_d_info.sd = 0;

	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}
//******************************************************
//set_acks();
//******************************************************
word32_t set_acks(bool_t *pAcksOk)
{
	word32_t acksAux = 0x00000000;//0
	uint8_t i = 31;

	for (i = 31; i >= 0; i--)
	{
		if (pAcksOk[i])
		{
			acksAux = acksAux + 0x00000001;//TODO:igual con 0x01 más que suficiente; depurar y comprobar
		}
		if (i != 0)
		{
			acksAux = acksAux << 1;
		}
	}
	return acksAux;
}

//******************************************************
//header_tc_frame();
//******************************************************
void sgi_link_layer_build_header_tc_frame(byte_t *pHeaderBurst, byte_t numberOfFrames)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_D_SGI;
	for (i = 0; i < 4; i++)
	{

		headerBurstAux.key[i] = 1;
		headerBurstAux.burst_type_info.type_d_info.acks[i] = 0xFF;

	}
	if (numberOfFrames > 32)
	{
		headerBurstAux.burst_type_info.type_d_info.nf = 32;
		headerBurstAux.crtl = MASK_SAT_TC_FRAMES;
	}
	else
	{
		headerBurstAux.burst_type_info.type_d_info.nf = numberOfFrames;
		headerBurstAux.crtl = MASK_LAST_SAT_TC_FRAMES;
	}
	headerBurstAux.burst_type_info.type_d_info.gc = 0;
	headerBurstAux.burst_type_info.type_d_info.ss = 0;
	headerBurstAux.burst_type_info.type_d_info.sd = 0;

	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}

//******************************************************
//build_tm_ack();
//******************************************************
//TODO: todos los valores que se ponen como 0 a fuego, pasar como parámetros
void sgi_link_layer_build_tm_ack(byte_t *pHeaderBurst, word32_t acks, bool_t last)//TODO: falta el bit alt
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_D_SGI;
	if (last)
	{
		headerBurstAux.crtl = MASK_LAST_SAT_TM_FRAMES_ACK;
	}
	else
	{
		headerBurstAux.crtl = MASK_SAT_TM_FRAMES_ACK;
	}
	for (i = 0; i < 4; i++)
	{

		headerBurstAux.key[i] = 1;
	}
	headerBurstAux.burst_type_info.type_d_info.acks[0] = acks;
	headerBurstAux.burst_type_info.type_d_info.acks[1] = acks >> 8;
	headerBurstAux.burst_type_info.type_d_info.acks[2] = acks >> 16;
	headerBurstAux.burst_type_info.type_d_info.acks[3] = acks >> 24;
	headerBurstAux.burst_type_info.type_d_info.nf = 0;
	headerBurstAux.burst_type_info.type_d_info.gc = 0;
	headerBurstAux.burst_type_info.type_d_info.ss = 0;
	headerBurstAux.burst_type_info.type_d_info.sd = 0;

	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}


//******************************************************
//build_sen_tm_tc_del_accept();
//******************************************************
void sgi_link_layer_build_sen_tm_tc_del_accept(byte_t *pHeaderBurst, bool_t alt, int32_t tryNumber, byte_t *pAltBit, word32_t sizeReq, word32_t sizeProvide)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_B_SGI;
	for (i = 0; i < 4; i++)
	{
		headerBurstAux.key[i] = 1;
		headerBurstAux.burst_type_info.type_b_info.size_req[i] = sizeReq;
		headerBurstAux.burst_type_info.type_b_info.size_provide[i] = sizeProvide;
	}
	if (tryNumber > 0)
	{
		headerBurstAux.crtl = MASK_SEN_TMTC_DEL_ACCEPT | MASK_REP_SGI;
	}
	else
	{
		headerBurstAux.crtl = MASK_SEN_TMTC_DEL_ACCEPT;
	}
	if (alt)
	{
		(*pAltBit) = sgi_link_layer_changes_alt_bit(&headerBurstAux.crtl, (*pAltBit));
	}
	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}

//******************************************************
//build_sen_tm_tc_del_req();
//******************************************************
void sgi_link_layer_build_sen_tm_tc_del_req(byte_t *pHeaderBurst, word32_t sizeReq, word32_t sizeProvide)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_B_SGI;
	for (i = 0; i < 4; i++)
	{
		headerBurstAux.key[i] = 1;
		headerBurstAux.burst_type_info.type_b_info.size_req[i] = sizeReq >> (8 * i);
		headerBurstAux.burst_type_info.type_b_info.size_provide[i] = sizeProvide >> (8 * i);
	}
	headerBurstAux.crtl = MASK_SEN_TMTC_DEL_REQ;
	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}

//******************************************************
//build_sen_tm_tc_del_end();
//******************************************************
void sgi_link_layer_build_sen_tm_tc_del_end(byte_t *pHeaderBurst, bool_t alt, int32_t tryNumber, byte_t *pAltBit)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_E_SGI;
	for (i = 0; i < 4; i++)
	{

		headerBurstAux.key[i] = 1;
		headerBurstAux.burst_type_info.type_e_info.stats_rx[i] = 0x00;
		headerBurstAux.burst_type_info.type_e_info.stats_tx[i] = 0x00;

	}
	if (tryNumber > 0)
	{
		headerBurstAux.crtl = MASK_SEN_TMTC_DEL_END | MASK_REP_SGI;
	}
	else
	{
		headerBurstAux.crtl = MASK_SEN_TMTC_DEL_END;
	}
	if (alt)
	{
		(*pAltBit) = sgi_link_layer_changes_alt_bit(&headerBurstAux.crtl, (*pAltBit));
	}
	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}
//******************************************************
//build_sen_tm_tc_del_end_ack();
//******************************************************
void sgi_link_layer_build_sen_tm_tc_del_end_ack(byte_t *pHeaderBurst)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_E_SGI;
	for (i = 0; i < 4; i++)
	{

		headerBurstAux.key[i] = 1;
		headerBurstAux.burst_type_info.type_e_info.stats_rx[i] = 0x00;
		headerBurstAux.burst_type_info.type_e_info.stats_tx[i] = 0x00;

	}
	headerBurstAux.crtl = MASK_SEN_TMTC_DEL_END_ACK;
	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}

//******************************************************
//build_sen_tc_sgi_header_frame();
//******************************************************
void sgi_link_layer_build_sen_tc_sgi_header_frame(byte_t *pHeaderBurst, byte_t numberOfFrames, bool_t alt, byte_t *pAltBit, word32_t acks)

{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;
	headerBurstAux.code = MASK_BURST_C_SGI;
	for (i = 0; i < 4; i++)
	{
		headerBurstAux.key[i] = 1;

	}
	for (i = 0; i < 3; i++)
	{
		headerBurstAux.burst_type_info.type_c_info.dummy[i] = 0;
	}

	if (numberOfFrames > 32)
	{
		headerBurstAux.burst_type_info.type_c_info.nf = 32;
		headerBurstAux.crtl = MASK_SEN_TC_SGI_LINK_FRAMES;
	}
	else
	{
		headerBurstAux.burst_type_info.type_c_info.nf = numberOfFrames;
		headerBurstAux.crtl = MASK_SEN_LAST_TC_SGI_LINK_FRAMES;
	}

	if (alt)
	{
		(*pAltBit) = sgi_link_layer_changes_alt_bit(&headerBurstAux.crtl, (*pAltBit));
	}
	headerBurstAux.burst_type_info.type_c_info.acks[0] = acks;
	headerBurstAux.burst_type_info.type_c_info.acks[1] = acks >> 8;
	headerBurstAux.burst_type_info.type_c_info.acks[2] = acks >> 16;
	headerBurstAux.burst_type_info.type_c_info.acks[3] = acks >> 24;
	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}

//******************************************************
//build_sen_tm_sgi_header_frame();
//******************************************************
void sgi_link_layer_build_sen_tm_sgi_header_frame(byte_t *pHeaderBurst, byte_t numberOfFrames, bool_t alt, int32_t tryNumber, byte_t *pAltBit, word32_t acks)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_C_SGI;
	for (i = 0; i < 4; i++)
	{
		headerBurstAux.key[i] = 1;
	}
	for (i = 0; i < 3; i++)
	{

		headerBurstAux.burst_type_info.type_c_info.dummy[i] = 0x00;
	}
	if (numberOfFrames > 32)
	{

		headerBurstAux.burst_type_info.type_c_info.nf = 32;
		headerBurstAux.crtl = MASK_SEN_TM_SGI_LINK_FRAMES;
	}
	else
	{
		headerBurstAux.burst_type_info.type_c_info.nf = numberOfFrames;
		headerBurstAux.crtl = MASK_SEN_LAST_TM_SGI_LINK_FRAMES;
	}
	if (tryNumber > 0)
	{
		headerBurstAux.crtl = headerBurstAux.crtl | MASK_REP_SGI;
	}
	if (alt)
	{
		(*pAltBit) = sgi_link_layer_changes_alt_bit(&headerBurstAux.crtl, (*pAltBit));
	}

	headerBurstAux.burst_type_info.type_c_info.acks[0] = acks;
	headerBurstAux.burst_type_info.type_c_info.acks[1] = acks >> 8;
	headerBurstAux.burst_type_info.type_c_info.acks[2] = acks >> 16;
	headerBurstAux.burst_type_info.type_c_info.acks[3] = acks >> 24;

	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}

//******************************************************
//build_sen_tm_sgi_frames_ack();
//******************************************************
void sgi_link_layer_build_sen_tm_sgi_frames_ack(byte_t *pHeaderBurst, word32_t acks, bool_t last)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	headerBurstAux.code = MASK_BURST_C_SGI;
	for (i = 0; i < 4; i++)
	{
		headerBurstAux.key[i] = 1;

	}
	for (i = 0; i < 3; i++)
	{

		headerBurstAux.burst_type_info.type_c_info.dummy[i] = 0x00;
	}
	headerBurstAux.burst_type_info.type_c_info.acks[0] = acks;
	headerBurstAux.burst_type_info.type_c_info.acks[1] = acks >> 8;
	headerBurstAux.burst_type_info.type_c_info.acks[2] = acks >> 16;
	headerBurstAux.burst_type_info.type_c_info.acks[3] = acks >> 24;
	headerBurstAux.burst_type_info.type_c_info.nf = 0;
	if (last)
	{
		headerBurstAux.crtl = MASK_SEN_LAST_TM_SGI_LINK_FRAMES_ACK;
	}
	else
	{
		headerBurstAux.crtl = MASK_SEN_TM_SGI_LINK_FRAMES_ACK;
	}
	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);

}

//******************************************************
//build_sen_tc_sgi_frames_ack();
//******************************************************
void sgi_link_layer_build_sen_tc_sgi_frames_ack(byte_t *pHeaderBurst, word32_t acks, bool_t alt, int32_t tryNumber, byte_t *pAltBit)
{
	SGI_burst_t headerBurstAux;
	uint8_t i = 0;

	//---define burst values
	headerBurstAux.code = MASK_BURST_C_SGI;
	for (i = 0; i < 4; i++)
	{
		headerBurstAux.key[i] = 1;
	}

	for (i = 0; i < 3; i++)
	{
		headerBurstAux.burst_type_info.type_c_info.dummy[i] = 0x00;
	}
	headerBurstAux.burst_type_info.type_c_info.nf = 0;

	if (tryNumber > 0)
	{
		headerBurstAux.crtl = MASK_SEN_TC_SGI_LINK_FRAMES_ACK | MASK_REP_SGI;
	}
	else
	{
		headerBurstAux.crtl = MASK_SEN_TC_SGI_LINK_FRAMES_ACK;
	}

	if (alt)
	{
		(*pAltBit) = sgi_link_layer_changes_alt_bit(&headerBurstAux.crtl, (*pAltBit));
	}
	headerBurstAux.burst_type_info.type_c_info.acks[0] = acks;
	headerBurstAux.burst_type_info.type_c_info.acks[1] = acks >> 8;
	headerBurstAux.burst_type_info.type_c_info.acks[2] = acks >> 16;
	headerBurstAux.burst_type_info.type_c_info.acks[3] = acks >> 24;
	//---burst values defined

	//--.build burst
	sgi_link_layer_build_header_burst(pHeaderBurst, headerBurstAux);
	sgi_link_layer_build_header_burst((pHeaderBurst + 16), headerBurstAux);
	//---burst builded

}

//******************************************************
//sgi_link_layer_changes_alt_bit();
//******************************************************
byte_t sgi_link_layer_changes_alt_bit(byte_t * ctrlFlags, byte_t altBit)
{
	(*ctrlFlags) = (*ctrlFlags) ^ altBit;
	return (altBit ^ MASK_ALT_SGI);
}

